package cn.yshujia.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

/**
 * @author YShuJia
 * @description 校验验证码 （一次性校验所以继承OncePerRequestFilter）
 * @create 2024/4/23
 */

@Slf4j
@Component
public class CaptchaFilter extends OncePerRequestFilter {
	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
		String url = request.getRequestURI();
		filterChain.doFilter(request, response);
		//登录请求验证
        /*if("/dologin".equals(url) && "GET".equals(request.getMethod())){
            //校验验证码
            String code = request.getHeader("code");
            if(code.isEmpty()){
                try {
                    log.info(" 进入验证码验证，登录请求，没有token，验证码错误！");
                    throw new Exception("验证码错误！");
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            else if("12345".equals(request.getHeader("code"))){
                log.info(" 进入验证码验证，登录请求，没有token，验证通过！");
                filterChain.doFilter(request, response);
            }
        }
        //其余请求放行
        else {
            filterChain.doFilter(request, response);
        }*/
	}
}
